home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vansi.zip / NANSI.ASM < prev    next >
Assembly Source File  |  1989-11-19  |  37KB  |  1,048 lines

  1.         page    66, 132
  2. ;--- nansi.asm ----------------------------------------------------------
  3. ; New ANSI terminal driver.
  4. ; Optimized for speed in the case of multi-character write requests.
  5. ; (C) 1986 Daniel Kegel, Pasadena, CA
  6. ; May be distributed for educational and personal use only
  7. ; The following files make up the driver:
  8. ;       nansi.asm   - all DOS function handlers except init
  9. ;       nansi_p.asm - parameter parser for ANSI escape sequences
  10. ;       nansi_f.asm - ANSI command handlers
  11. ;       nansi_i.asm - init DOS function handler
  12. ;
  13. ; Daniel Kegel, Bellevue, Washington & Pasadena, California
  14. ; Revision history:
  15. ; 5  july 85: brought up non-ANSI portion except forgot backspace
  16. ; 6  july 85: split off ANSI stuff into other files, added backspace
  17. ; 11 july 85: fixed horrible bug in getchar; changed dosfns to subroutines
  18. ; 12 july 85: fixed some scrolling bugs, began adding compaq flag
  19. ; 9  aug 85:  added cursor position reporting
  20. ; 10 aug 85:  added output character translation
  21. ; 11 aug 85:  added keyboard redefinition, some EGA 80x43 support
  22. ; 10 sept 85: Tandy 2000 support via compaq flag (finding refresh buffer)
  23. ; 30 Jan 86:  removed Tandy 2000 stuff, added graphics mode support
  24. ; 12 feb 86:  added int 29h handler, added PUSHA/POPA, added direct beep,
  25. ;             direct cursor positioning, takeover of BIOS write_tty,
  26. ;             noticed & squashed 2 related bugs in tab expansion
  27. ; 13 feb 86:  Squashed them again, harder
  28. ;------------------------------------------------------------------------
  29.  
  30.         include nansi_d.asm     ; definitions
  31.  
  32.         ; from nansi_f.asm
  33.         extrn   f_escape:near, f_in_escape:near
  34.  
  35.         ; from nansi_p.asm
  36.         extrn   param_end:word, redef_end:word
  37.  
  38.         ; from nansi_i.asm
  39.         extrn   dosfn0:near
  40.  
  41.         ; to nansi_p.asm
  42.         public  f_loopdone
  43.         public  f_not_ansi
  44.         public  f_ansi_exit
  45.  
  46.         ; to both nansi_p.asm and nansi_f.asm
  47.         public  cur_x, cur_y, max_x, cur_attrib
  48.  
  49.         ; to nansi_f.asm
  50.         public  xy_to_regs, get_blank_attrib
  51.         public  port_6845
  52.         public  wrap_flag
  53.         public  cur_parm_ptr
  54.         public  cur_coords, saved_coords, max_y
  55.         public  escvector, string_term
  56.         public  cpr_esc, cprseq
  57.         public  video_mode
  58.         public  lookup
  59.         public  in_g_mode
  60.  
  61.         ; to nansi_i.asm
  62.         public  req_ptr, break_handler
  63.         public  int_29
  64.         if      takeBIOS
  65.         public  new_vid_bios, old_vid_bios
  66.         endif
  67.  
  68.         ; to all modules
  69.         public  xlate_tab_ptr
  70.  
  71. ;--- seg_cs is the CS: override prefix
  72. ; (assembler forgets cs: on second "xlat dummy_cs_byte")
  73. seg_cs  macro
  74.         db      2eh
  75.         endm
  76.  
  77. ;--- push_all, pop_all ------------------------------------------------
  78. ; Save/restore all user registers.
  79. push_all        macro
  80.         if      is_8088
  81.         push    ax
  82.         push    bx
  83.         push    cx
  84.         push    dx
  85.         push    bp
  86.         push    si
  87.         push    di
  88.         else
  89.         pusha
  90.         endif
  91.         endm
  92.  
  93. pop_all macro
  94.         if      is_8088
  95.         pop     di
  96.         pop     si
  97.         pop     bp
  98.         pop     dx
  99.         pop     cx
  100.         pop     bx
  101.         pop     ax
  102.         else
  103.         popa
  104.         endif
  105.         endm
  106.  
  107. keybuf  struc                           ; Used in getchar
  108. len     dw      ?
  109. adr     dw      ?
  110. keybuf  ends
  111.  
  112.  
  113. ABS40   segment at 40h
  114.         org     1ah
  115. buffer_head     dw      ?       ; Used in 'flush input buffer' dos call.
  116. buffer_tail     dw      ?
  117.  
  118.         org     49h
  119. crt_mode        db      ?
  120. crt_cols        dw      ?
  121. crt_len         dw      ?
  122. crt_start       dw      ?
  123. cursor_posn     dw      8 dup (?)
  124. cursor_mode     dw      ?
  125. active_page     db      ?
  126. addr_6845       dw      ?
  127. crt_mode_set    db      ?       ; = 7 only if monochrome display adaptor
  128. crt_palette     db      ?
  129.         org     6ch
  130. timer_low       dw      ?       ; low word of time-of-day counter (18.2 hz)
  131.         org 84h
  132. crt_max_y       db ?            ; CJD 11/19/89 - EGA/VGA max row #
  133. ABS40   ends
  134.  
  135.         page
  136.  
  137. CODE    segment byte public 'CODE'
  138. assume  cs:code, ds:code
  139.  
  140.         ; Device Driver Header
  141.  
  142.         org     0
  143.  
  144.         dd      -1                      ; next device
  145.         dw      8013h                   ; attributes
  146.         dw      strategy                ; request header pointer entry
  147.         dw      interrupt               ; request entry point
  148.         db      'CON     '              ; device name (8 char)
  149.  
  150.         ; Identification- in case somebody TYPEs the assembled driver
  151.         db      27, '[2J'
  152.         db      "Nansi.sys v2.2"
  153.         ife     is_8088
  154.         db      "(80286)"
  155.         endif
  156.         db      ': New ANSI driver (C) Daniel Kegel, Pasadena, CA 1986'
  157.         db      13, 10, 26
  158.  
  159.  
  160. ;----- variable area --------------------
  161. req_ptr label   dword
  162. req_off dw      ?
  163. req_seg dw      ?
  164.  
  165. wrap_flag       db      1       ; 0 = no wrap past line end
  166. escvector       dw      0       ; state vector of ESCape sequencor
  167. video_mode      db      3       ; ROM BIOS video mode (2=BW, 3=color)
  168. max_y           db      24
  169. max_cur_x       label   word    ; used to get both max & cur at once
  170. max_x           db      79      ; line width (79 for 80x25 modes)
  171. cur_coords      label   word
  172. cur_x           db      0       ; cursor position (0 = left edge)
  173. cur_y           db      0       ;                 (0 = top edge)
  174. saved_coords    dw      ?       ; holds XY after a SCP escape sequence
  175. string_term     db      0       ; either escape or double quote
  176. cur_attrib      db      7       ; current char attributes
  177. cur_page        db      0       ; current display page
  178. video_seg       dw      ?       ; segment of video card
  179. f_cptr_seg      dw      ?       ; part of fastout write buffer pointer
  180. cur_parm_ptr    dw      ?       ; last byte of parm area now used
  181. port_6845       dw      ?       ; port address of 6845 card
  182. xlate_tab_ptr   dw      ?       ; pointer to output translation table
  183.                 if      takeBIOS
  184. old_vid_bios    dd      ?       ; pointer to old video bios routine
  185.                 endif
  186.  
  187. brkkeybuf       db      3       ; control C
  188. fnkeybuf        db      ?       ; holds second byte of fn key codes
  189. cpr_buf         db      8 dup (?), '['
  190. cpr_esc         db      1bh     ; descending buffer for cpr function
  191.  
  192. ; following four keybufs hold information about input
  193. ; Storage order determines priority- since the characters making up a function
  194. ; key code must never be separated (say, by a Control-Break), they have the
  195. ; highest priority, and so on.  Keyboard keys (except ctrl-break) have the
  196. ; lowest priority.
  197.  
  198. fnkey   keybuf  <0, fnkeybuf>   ; fn key string (0 followed by scan code)
  199. cprseq  keybuf  <0>             ; CPR string (ESC [ y;x R)
  200. brkkey  keybuf  <0, brkkeybuf>  ; ^C
  201. xlatseq keybuf  <0>             ; keyboard reassignment string
  202.  
  203. ;------ xy_to_regs --------------------------------------------
  204. ; on entry: x in cur_x, y in cur_y
  205. ; on exit:  dx = chars left on line, di = address
  206. ; Alters ax, bx.
  207. xy_to_regs      proc    near
  208.         ; Find number of chars 'till end of line, keep in DX
  209.         mov     ax, max_cur_x
  210.         mov     bx, ax                  ; save max_x & cur_x for next block
  211.         mov     ah, 0                   ; ax = max_x
  212.         xchg    dx, ax
  213.         mov     al, bh
  214.         mov     ah, 0                   ; ax = cur_x
  215.         sub     dx, ax
  216.         inc     dx                      ; dx is # of chars till EOL
  217.         ; Calculate DI = current address in text buffer
  218.         mov     al, bl                  ; al = max_x
  219.         inc     al
  220.         mul     cur_y
  221.         add     al, bh                  ; al += cur_x
  222.         adc     ah, 0                   ; AX is # of chars into buffer
  223.         add     ax, ax
  224.         xchg    di, ax                  ; DI is now offset of cursor.
  225.         ret
  226. xy_to_regs      endp
  227.  
  228.  
  229. ;------- dos_fn_tab -------------
  230. ; This table is used in "interrupt" to call the routine that handl